﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChartTools
{
    /// <summary>
    /// 3D柱状图
    /// </summary>
    public class Column3D
    {
        public string Title { get; set; }
        public string XName { get; set; }
        public string YName { get; set; }
        public List<Column3DData> Datas { get; set; }
        public string AVGLine { get; set; }
        public string FunctionName { get; set; }
        public string DivId { get; set; }

        private Column3D() { }

        public Column3D(string title, string xname, string yname, List<Column3DData> datas, string avgline, string functionname, string divid)
        {
            this.Title = title;
            this.XName = xname;
            this.YName = yname;
            this.Datas = datas;
            this.AVGLine = avgline;
            this.FunctionName = functionname;
            this.DivId = divid;
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<chart caption='" + Title + "' xAxisName='" + XName + "' yAxisName='" + YName + "' showValues='0' decimals='0' formatNumberScale='0' palette='4'>");
            foreach (Column3DData data in Datas)
            {
                sb.Append("<set label='" + data.Name + "' value='" + data.Value + "' />");
            }
            if (!string.IsNullOrEmpty(AVGLine))
            {
                sb.Append("<trendlines>");
                sb.Append("<line startValue='" + AVGLine + "' displayValue='Average' color='009900' valueOnRight='1' />");
                sb.Append("</trendlines>");
            }
            sb.Append("</chart>");
            string datas = sb.ToString();
            sb = new StringBuilder();
            sb.AppendLine("<script type=\"text/javascript\">");
            sb.Append("            function ");
            sb.Append(FunctionName);
            sb.AppendLine("(){");
            sb.AppendLine("                var chart = new FusionCharts(\"/Content/FusionCharts/Column3D.swf\", \"ChartId\", \"100%\", \"260\", \"0\", \"0\");");
            sb.AppendLine("                chart.setXMLData(\"" + datas + "\");");
            sb.AppendLine("                chart.render(\"" + DivId + "\");");
            sb.AppendLine("             }");
            sb.AppendLine("        </script>");
            return sb.ToString();
        }
    }

    public class Column3DData
    {
        public string Name { get; set; }

        public decimal Value { get; set; }
    }
}
